package com.liss.lissaiagent.tool;


import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
import com.liss.lissaiagent.constant.FileConstant;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;

import java.io.File;

/**
 * @Author: Mr.Li
 * @CreateTime: 2025-10-15
 * @Description: 资源下载
 * @Version: 1.0
 */
public class ResourceDownloadTool {


    @Tool(description = "Download a resource from a given URL")
    public String downLoadResources(@ToolParam(description = "URL of the resource to download") String url,
                                   @ToolParam(description = "Name of the file to save the downloaded resource") String fileName
    ) {
        String fileDir = FileConstant.FILE_SAVE_DIR + "/download";
        String filePath = fileDir + "/" + fileName;
        try {

            FileUtil.mkdir(fileDir);

            HttpUtil.downloadFile(url, new File(filePath));
            return "Resource downloaded successfully to: " + filePath;
        } catch (Exception e) {
            return "Error downloading resource: " + e.getMessage();
        }
    }
}
